<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"/>
    <title>文章评论管理中新</title>
    <link rel="stylesheet" href="/layui/plugins/layui/css/layui.css" media="all" />
    <script src="/layui/plugins/layui/layui.js"></script>
    <script src="/main/js/jquery.min.js"></script>
    <style>
        body{margin: 10px;}
        .demo-carousel{height: 200px; line-height: 200px; text-align: center;}
    </style>
</head>
<body>

<div style="margin: 15px;">
    <fieldset class="layui-elem-field">
        <legend>文章评论管理中心 </legend>
        <table id="comList" class="layui-table" lay-filter="comDemo">
        </table>
    </fieldset>
</div>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-mini" lay-event="del">删除评论</a>
</script>
<script>
    var paperId = parent.id;
    layui.use(['layer', 'table', 'element'], function(){

          layer = layui.layer;//弹层
          table = layui.table; //表格

//        table.init('filter', options); //转化静态表格
        table.render({
//            id:'comid',
            elem:'#comList',
            width:650,
//            page:'true',
            url:'/comments/ByPaperId/'+paperId,
            cols: [[
                {field:'id', title: '#', width:20}
                ,{field:'content', title: '评论内容', width:350}
                ,{field:'time', title: '评论时间', width:170}
                ,{toolbar:'#barDemo', title: '操作', width:74}
            ]]
        });

            //监听工具条
            table.on('tool(comDemo)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                var data = obj.data //获得当前行数据
                , layEvent = obj.event; //获得 lay-event 对应的值
                if (layEvent === 'detail') {
                    layer.msg('查看操作');
                    // 为文章添加一个标签.删除某个标签 不做分页
                } else if (layEvent === 'del') {
                    layer.confirm('真的删除行么', function (index) {
                        obj.del(); //删除对应行（tr）的DOM结构
                        var id = data.id;
                        $.ajax({
                            url:'/comments/deleteComment/'+id,    //请求的url地址
                            dataType:"json",   //返回格式为json
                            type:"GET",   //请求方式
                            success:function (data) {
                                if (data == '1'){
                                    layer.confirm('删除成功')
                                }
                                else {
                                    layer.confirm('删除出错')
                                }
                            }
                        });
                        layer.close(index);
                    });
                }
            });

    });

</script>

</body>
</html>